package cn.ffcs.uec.staff.dao.impl;

import java.util.ArrayList;
import java.util.List;

import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

import cn.ffcs.uec.staff.dao.UecFamilyDao;
import cn.ffcs.uec.staff.model.UecFamily;
import cn.ffcs.uec.staffAndOutStaff.vo.StaffAndOutStaff;
import cn.ffcs.uom.common.constants.BaseUnitConstants;
import cn.ffcs.uom.common.dao.BaseDaoImpl;
import cn.ffcs.uom.common.util.StrUtil;
import cn.ffcs.uom.common.vo.PageInfo;

@Repository("uecFamilyDao")
@Transactional
public class UecFamilyDaoImpl extends BaseDaoImpl implements UecFamilyDao {

	@Override
	public PageInfo queryPageInfoByUecFamily(UecFamily uecFamily, int current,
			int pageSize) {
		if (null != uecFamily) {
			StringBuilder sb = new StringBuilder(
					" SELECT * FROM UEC_FAMILY T WHERE 1 = 1 ");
			List<Object> params = new ArrayList<Object>();
			sb.append(" AND T.STATUS_CD = ? ");
			params.add(BaseUnitConstants.ENTT_STATE_ACTIVE);

			//判断这个对象是外包人员的数据还是合同制的数据
			if (BaseUnitConstants.NM_OUT_STAFF_TYPE.equals(uecFamily.getNmStaffType())) {
				sb.append(" AND T.NM_STAFF_TYPE = ? ");
				params.add(BaseUnitConstants.NM_OUT_STAFF_TYPE);
			}
			
			if (!StrUtil.isNullOrEmpty(uecFamily.getPkPsndoc())) {//判断数据是否是集团的
				sb.append(" AND T.PK_PSNDOC = ? ");
				params.add(uecFamily.getPkPsndoc());
			} else if (!StrUtil.isNullOrEmpty(uecFamily.getStaffId())) {
				sb.append(" AND T.STAFF_ID = ? ");
				params.add(uecFamily.getStaffId());
			}
			return this.jdbcFindPageInfo(sb.toString(), params, current,
					pageSize, UecFamily.class);
		}
		return null;
	}

	@Override
	public UecFamily queryUecFamilyById(UecFamily uecFamily) {
		if (null != uecFamily) {
			StringBuilder sb = new StringBuilder(
					" SELECT * FROM UEC_FAMILY T WHERE 1 = 1 ");
			
			List<Object> params = new ArrayList<Object>();
			
			if (!StrUtil.isNullOrEmpty(uecFamily.getFamilyId())) {
				sb.append(" AND T.family_id = ? ");
				params.add(uecFamily.getFamilyId());
			}
			
			return this.jdbcFindObject(sb.toString(), params, UecFamily.class);
			
		}
		return uecFamily;
	}

	@Override
	public PageInfo queryPageInfoByUecFamilyOnApproval(UecFamily uecFamily,
			int current, int pageSize) {
		if (null != uecFamily) {
			StringBuilder sb = new StringBuilder(
					" SELECT * FROM UEC_FAMILY T WHERE 1 = 1 ");
			List<Object> params = new ArrayList<Object>();
			sb.append(" AND T.STATUS_CD = ? ");
			params.add(BaseUnitConstants.ENTT_STATE_PROCESS);

			//判断这个对象是外包人员的数据还是合同制的数据
			if (BaseUnitConstants.NM_OUT_STAFF_TYPE.equals(uecFamily.getNmStaffType())) {
				sb.append(" AND T.NM_STAFF_TYPE = ? ");
				params.add(BaseUnitConstants.NM_OUT_STAFF_TYPE);
			}
			
			if (!StrUtil.isNullOrEmpty(uecFamily.getPkPsndoc())) {//判断数据是否是集团的
				sb.append(" AND T.PK_PSNDOC = ? ");
				params.add(uecFamily.getPkPsndoc());
			} else if (!StrUtil.isNullOrEmpty(uecFamily.getStaffId())) {
				sb.append(" AND T.STAFF_ID = ? ");
				params.add(uecFamily.getStaffId());
			}
			return this.jdbcFindPageInfo(sb.toString(), params, current,
					pageSize, UecFamily.class);
		}
		return null;
	}

	@Override
	public List<UecFamily> getUecFamilyListByPkpsndoc(StaffAndOutStaff uecOutStaffInfo) {
		if (null != uecOutStaffInfo) {
			StringBuilder sb = new StringBuilder(
					" SELECT * FROM UEC_FAMILY T WHERE 1 = 1 ");
			List<Object> params = new ArrayList<Object>();
			sb.append(" AND T.STATUS_CD = ? ");
			params.add(BaseUnitConstants.ENTT_STATE_PROCESS);
			
			if (!StrUtil.isNullOrEmpty(uecOutStaffInfo.getPkPsndoc())) {//判断数据是否是集团的
				sb.append(" AND T.PK_PSNDOC = ? ");
				params.add(uecOutStaffInfo.getPkPsndoc());
			}
			return this.jdbcFindList(sb.toString(), params, UecFamily.class);
		}
		return null;
	}
}
